package top.springcloud.order.service.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.springcloud.order.entity.Order;
import top.springcloud.order.mapper.OrderMapper;
import top.springcloud.order.service.OrderService;

/**
 * @ClassName OrderServiceImpl
 * @Description orderService
 * @Author 维康
 * @Date 2018/8/16 14:13
 * @Version 1.0
 **/
@Service("orderService")
public class OrderServiceImpl  implements OrderService {

    @Autowired
    private OrderMapper orderMapper;

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Override
    public Order saveOrder(Order order) {
        if(order.getOrderId()!=null){
            orderMapper.updateById(order);
        }else{
            orderMapper.insert(order);
        }
        logger.info("save order : "+order);
        return order;
    }

    @Override
    public Order getOrderByOrderId(Long orderId) {
        Order order = orderMapper.selectById(orderId);
        logger.info("get order : "+order);
        return order;
    }

    @Override
    public int deleteOrder(Long orderId) {
        return orderMapper.deleteById(orderId);
    }
}
